import { GlobalStore } from "@/stores";
import logo from "@/assets/images/logo.png";
import { SYSTEM_ID } from "@/config/config";
import { AuthStore } from "@/stores/modules/auth";

/**
 * @description 获取本地时间
 */
export const sysTitle = () => {
	return GlobalStore().setting.isSysTitle ? GlobalStore().setting.systemName || import.meta.env.VITE_GLOB_APP_TITLE : "";
};
export const version = () => {
	return (SYSTEM_ID + import.meta.env.VITE_APP_VER) as string;
};
export const sysLogo = () => {
	return GlobalStore().setting.logo == logo ? logo : `${filePrefix()}${GlobalStore().setting.logo}`;
};
export const filePrefix = () => {
	return "/api/file/download/";
};
export const getDefaultMenu = (path?: string) => {
	function getMenu(menu: Menu.MenuOptions): Menu.MenuOptions | undefined {
		if (menu?.children?.length) {
			for (let i in menu.children) {
				let child = getMenu(menu.children[i]);
				if (child?.path && path != child?.path) {
					return child;
				}
			}
		} else if (menu?.path && path != menu?.path) {
			return menu;
		}
	}

	let list = AuthStore().authMenuList;
	let res;
	for (let i in list) {
		let menu = list[i];
		res = getMenu(menu);
		if (res) {
			break;
		}
	}
	// console.log(res);
	return res;
};
